
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region Subject Model -(by fangyifeng at 2006-10-30 11:49:37)

	/// <summary>
	/// Subject object'Subject'.
	/// </summary>
	[Serializable]
	public class Subject : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _name;
        protected string _SceneName;
		protected DateTime _createDate;
		protected string _discription;
		protected string _categories;
		protected string _newsCategories;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public Subject() { }

		public Subject( string name, DateTime createDate,string scenename, string discription, string categories, string newsCategories )
		{
            this._SceneName = scenename;
			this._name = name;
			this._createDate = createDate;
			this._discription = discription;
			this._categories = categories;
			this._newsCategories = newsCategories;
		}

		#endregion

		#region Public Properties

        public virtual string SceneName
        {
            get
            {
                return _SceneName;
            }
            set
            {
                _SceneName = value;
            }
        }

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string Name
		{
			get { return _name; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
				_name = value;
			}
		}

		public virtual DateTime CreateDate
		{
			get { return _createDate; }
			set { _createDate = value; }
		}

		public virtual string Discription
		{
			get { return _discription; }
			set
			{
				if ( value != null && value.Length > 1000)
					throw new ArgumentOutOfRangeException("Invalid value for Discription", value, value.ToString());
				_discription = value;
			}
		}

		public virtual string Categories
		{
			get { return _categories; }
			set
			{
                if (value != null && value.Length > 3800)
					throw new ArgumentOutOfRangeException("Invalid value for Categories", value, value.ToString());
				_categories = value;
			}
		}

		public virtual string NewsCategories
		{
			get { return _newsCategories; }
			set
			{
				if ( value != null && value.Length > 1000)
					throw new ArgumentOutOfRangeException("Invalid value for NewsCategories", value, value.ToString());
				_newsCategories = value;
			}
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is Subject))
				throw new InvalidCastException("This object is not of type Subject");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((Subject)obj).Id);
					break;
				case "Name":
					relativeValue = this.Name.CompareTo(((Subject)obj).Name);
					break;
				case "CreateDate":
					relativeValue = this.CreateDate.CompareTo(((Subject)obj).CreateDate);
					break;
				case "Discription":
					relativeValue = (this.Discription != null) ? this.Discription.CompareTo(((Subject)obj).Discription) : -1;
					break;
				case "Categories":
					relativeValue = (this.Categories != null) ? this.Categories.CompareTo(((Subject)obj).Categories) : -1;
					break;
				case "NewsCategories":
					relativeValue = (this.NewsCategories != null) ? this.NewsCategories.CompareTo(((Subject)obj).NewsCategories) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (Subject.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
